<?php
/**
 * Created by PhpStorm.
 * User: xieky
 * Date: 2017/8/3
 * Time: 11:53
 */

namespace common\repositories\myhtsq;

use common\repositories\BaseRepository;
use common\entities\myhtsq\ContractRevenueCarryoverEntity;


class ContractRevenueCarryoverRepository extends BaseRepository
{
    /**
     * 构造方法
     * @param unknown $config (optional)
     */
    public function __construct($config = [])
    {
        parent::__construct($config);
    }

    /**
     * 获取结转数据列表
     * @param $contrctguid
     */
    public static function getCarryoverListByContractId($contrctguid){
        $sql = "SELECT
                c.*,
                r.revenue_id,
                r.income_code,
                r.amount
                FROM myscrm_contract_revenue_carryover c
                inner join myscrm_contract_revenue r on c.revenue_id=r.revenue_id
                WHERE r.contract_id=:contractguid
                ";
        $conn = ContractRevenueCarryoverEntity::getDb();
        return $conn->createCommand($sql,[':contractguid'=>$contrctguid])->queryAll();
    }

    /**
     *
     * @param $oid
     */
    public static function getCarryoverById($oid){
        return ContractRevenueCarryoverEntity::find()->select(['carryover_id'=>$oid])->one();
    }
}